{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.dea3d5c36926caa04d36ce7adec54b48.315360000.1918875070.282335-22868820', 'expires_in': 2592000, 'session_key': '9mzdWEnM/SHsvJ+Klzwf8ezSazKt885iu7kanyrUwoME4Ky0iFHyMEBvMFsZvAnAWnvrW6xnpP4l/A8vMpJ3xEHy6VPyGA==', 'access_token': '24.c9f9b7d09757b461cff713ea9e0c4f53.2592000.1606107070.282335-22868820', 'scope': 'public brain_all_scope vis-faceverify_faceverify_h5-face-liveness vis-faceverify_FACE_V3 vis-faceverify_idl_face_merge vis-faceverify_FACE_EFFECT vis-faceverify_face_feature_sdk wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component', 'session_secret': '42e3990d51d19d485a0721d223b3069e'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=MLkobeqTMgBiYWf8szCzRxdu&client_secret=U6U38dSoMi4AEzQwVxGWrxWEAKFLubnV'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 2575551565001, 'timestamp': 1603515794, 'cached': 0, 'result': {'face_num': 1, 'face_list': [{'face_token': '84efc818d35f82978e426600a99bbde5', 'location': {'left': 1067.31, 'top': 375.19, 'width': 440, 'height': 446, 'rotation': -2}, 'face_probability': 1, 'angle': {'yaw': 3.13, 'pitch': 7.6, 'roll': -4.03}, 'face_shape': {'type': 'oval', 'probability': 0.7}, 'face_type': {'type': 'human', 'probability': 0.99}}]}}\n"
     ]
    }
   ],
   "source": [
    "# 人脸检测与属性分析\n",
    "\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/detect\"\n",
    "\n",
    "params = \"{\\\"image\\\":\\\"https://gitee.com/fanpeikun/my-ku/raw/master/f692a03cb7fbc3545eac264b18fc2367.jpeg\\\",\\\"image_type\\\":\\\"URL\\\",\\\"face_field\\\":\\\"faceshape,facetype\\\"}\"\n",
    "access_token = '24.c9f9b7d09757b461cff713ea9e0c4f53.2592000.1606107070.282335-22868820'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 0,\n",
       " 'error_msg': 'SUCCESS',\n",
       " 'log_id': 520115997915,\n",
       " 'timestamp': 1603517697,\n",
       " 'cached': 0,\n",
       " 'result': {'score': 76.50760651,\n",
       "  'face_list': [{'face_token': '03f6a93605cf596adbdec9efc1901897'},\n",
       "   {'face_token': 'c5e40a06bd2db3614e8cd8a65da7d34d'}]}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 人脸对比\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/match\"\n",
    "\n",
    "params = \"[{\\\"image\\\": \\\"https://gitee.com/fanpeikun/my-ku/raw/master/20191214152337.jpg\\\", \\\"image_type\\\": \\\"URL\\\", \\\"face_type\\\": \\\"CERT\\\", \\\"quality_control\\\": \\\"LOW\\\"}, {\\\"image\\\": \\\"https://gitee.com/fanpeikun/my-ku/raw/master/41c37c09abd946e4da3abaf6f7f1234f.jpg\\\", \\\"image_type\\\": \\\"URL\\\", \\\"face_type\\\": \\\"LIVE\\\", \\\"quality_control\\\": \\\"LOW\\\"}]\"\n",
    "# face_type 人脸的类型 LIVE；IDCARD；WATERMARK；CERT；INFRARED。\n",
    "\n",
    "access_token = '24.c9f9b7d09757b461cff713ea9e0c4f53.2592000.1606107070.282335-22868820' # 调用鉴权接口获取的token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/json'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
